package czopyk.tests;

import java.io.File;
import java.util.Date;

import model.Time;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

import pl.czopyk.view.QuickDrawer;
import czopyk.model.factories.Locator;

public class AbstractTest {

	private static final Logger lgr = Logger.getLogger(AbstractTest.class);
	
	private static final String PATTERN = "%-5p %-25c{1} : %m%n";

	public AbstractTest(String modelFilename, String controllerFilename,
			Level loggingLevel) throws Exception {
		this(modelFilename, controllerFilename, loggingLevel, true);
	}

	public AbstractTest(String modelFilename, String controllerFilename,
			Level loggingLevel, boolean b) {
		QuickDrawer.off = !b;
		ConsoleAppender ca = new ConsoleAppender(new PatternLayout(PATTERN));
		ca.setThreshold(loggingLevel);
		BasicConfigurator.configure(ca);

		try {
			Locator.loadSimulation(modelFilename, controllerFilename);
			Time.run();
			QuickDrawer.write(new File("").getAbsolutePath() + "/src/main/resources/data/" + new Date().getTime() + ".dat");
			QuickDrawer.draw();		
		} catch (Exception e) {
			lgr.error("Initialization failed: " + e.getMessage());
			e.printStackTrace();
		}
	}

}
